package com.socialrss.utils.twitter;

import java.util.List;

import twitter4j.Friendship;
import twitter4j.IDs;
import twitter4j.ResponseList;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.UserList;
import twitter4j.auth.AccessToken;
import twitter4j.conf.ConfigurationBuilder;
import twitter4j.Status;
import com.socialrss.R;
import com.socialrss.accounts.AccountOwner;
import com.socialrss.accounts.FollowedPerson;
import com.socialrss.constants.SocialNetworkNames.SocialNetKeys;
import com.socialrss.utils.SocialRssModel;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

public class Twitts extends Thread{
	
	private Context context;
	public Twitts(Context con) {
		context = con;
	}
	@Override
	public void run() {
		Log.d("Twitts Thread", "Twitter Thread Started");
		try {
			ConfigurationBuilder builder = new ConfigurationBuilder();
			builder.setOAuthConsumerKey(TwitterUtil.TWITTER_CONSUMER_KEY);
			builder.setOAuthConsumerSecret(TwitterUtil.TWITTER_CONSUMER_SECRET);

			AccountOwner owner = SocialRssModel.Instance(null).getAccessTokenOfSocialNet(SocialNetKeys.tw.toString());
			// Access Token
			String access_token = owner.getAccessToken();
			// Access Token Secret
			String access_token_secret = owner.getSecret_token();
			
			AccessToken accessToken = new AccessToken(access_token, access_token_secret);
			Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
			// Get twitter list
			List<twitter4j.Status> statuses = twitter.getHomeTimeline();
            for (twitter4j.Status status : statuses) {
                System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
//                FollowedPerson conn = SocialRssModel.Instance(null).getConnectionWithUserId(userid, SocialNetKeys.ins);
//                if(conn != null){
//                	if(conn.isTurnedOn()){
//                		
//                	}
//                }
                
                
//                SocialRssModel.Instance(context).insertNotification(SocialNetKeys.tw, conn);				//give FollowedPerson parameter
            }
		} catch (TwitterException e) {
			// Error in updating status
			Log.d("Twitter Update Error", e.getMessage());
		}
		Log.d("Twitts Thread", "Twitter Thread Ended");
	}	

	
}

